package servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ViewPatientServlet extends BaseServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);
	}

	private void process(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Integer patientId = Integer.parseInt(""
				+ request.getParameter("patientId"));

		Patient patient = PatientManager.getInstance().getPatient(patientId);
		ArrayList<ConsultationRecord> consultationRecords = PatientManager.getInstance().geConsultationRecordByPatientId(patientId);
		ArrayList<LabTestRecord> labTestRecords = PatientManager.getInstance().getLabTestRecords(patientId);
		
		ArrayList<LabTest> labTests = LabTestManager.getInstance().getAllLabTest();
		
		request.setAttribute("labTests", labTests);
		
		request.setAttribute("labTestRecords", labTestRecords);
		request.setAttribute("consultationRecords", consultationRecords);
		request.setAttribute("patient", patient);
		
		forward(request, response, "/view_patient.jsp");
	}

}
